/*

 * @(#)XlsFile.java

 */

package com.stony.poie.basic;

import com.stony.poie.ext.XlsStyle;

/**
 * A XlsFile is respond to an excel file.
 * <p>
 * Last modified: February 13, 2006
 * 
 * @author Thomas Wu
 * @version 1.0.0
 */

public final class XlsFile {

	/** Custom styles number allowance. */

	public final static int CUSTOM_STYLES_NUM = 10;

	/** Total styles number (there are 3 build in styles). */

	public final static int TOTAL_STYLES_NUM = CUSTOM_STYLES_NUM + 3;

	/* Sheets stored in the XlsFile. */

	private XlsTable tables[];

	/* Styles stored in the XlsFile. */

	private XlsStyle styles[];

	/**
	 * Construct a new XlsFile contains an array of XlsTable.
	 * 
	 * @param tables
	 *            tables stored in the XlsFile.
	 */

	public XlsFile(XlsTable tables[]) {

		this.tables = tables;

		this.styles = new XlsStyle[CUSTOM_STYLES_NUM + 3];

		int i = 0;

		for (i = 0; i < CUSTOM_STYLES_NUM; i++) {
			styles[i] = new XlsStyle();
		}

		i = CUSTOM_STYLES_NUM;

		styles[i + 0] = new XlsStyle(); /* Default style. */

		styles[i + 1] = new XlsStyle("yyyy-mm-dd"); /* Date style. */

		styles[i + 2] = new XlsStyle("#,##0.0000"); /* Currency style. */

	}

	/** Overloaded constructor. */

	public XlsFile(XlsTable table) {

		this(new XlsTable[] { table });

	}

	/** Overloaded constructor. */

	public XlsFile(int num) {

		this(new XlsTable[num]);

	}

	/** Overloaded constructor. */

	public XlsFile() {

		this(new XlsTable[1]);

	}

	/**
	 * 
	 * @return Sheets stored in the XlsFile.
	 * 
	 */

	public XlsTable[] getTables() {

		return tables;

	}

	/**
	 * 
	 * @param index
	 *            index of a sheet in the sheets array
	 * 
	 * @param sheet
	 *            sheet to be set
	 * 
	 */

	public void setTable(int index, XlsTable sheet) {

		tables[index] = sheet;

	}

	/**
	 * 
	 * @param index
	 *            index of a sheet in the sheets array
	 * 
	 * @return style stored at the specified index in the styles array
	 * 
	 */

	public XlsStyle getStyle(int index) {

		if (index < TOTAL_STYLES_NUM && index >= 0) {

			return styles[index];

		} else {

			return styles[CUSTOM_STYLES_NUM + 1];

		}

	}

	/**
	 * 
	 * @param index
	 *            index of a sheet in the sheets array
	 * 
	 * @param style
	 *            style stored at the specified index in the styles array
	 * 
	 */

	public void setStyle(int index, XlsStyle style) {

		if (index >= 0 && index < CUSTOM_STYLES_NUM) {

			this.styles[index] = style;

		}

	}

}